package com.cti.ftpservice.vo;

import java.io.IOException;

import com.cti.ftpservice.ftp.FTPDownLoadXmlFiles;
import com.cti.ftpservice.ftp.FileUtils;

public class FtpOnixXmlInfoVo extends FtpDownLoadBaseServiceInfoVo{

	@Override
	public void startDownLoadFiles() throws InterruptedException, NumberFormatException, IOException {
		setStop(false);
		for (int i = 1; i <= getThreadCount(); i++) {
			FTPDownLoadXmlFiles ftpDownFiles = new FTPDownLoadXmlFiles(this);
			Thread thread = new Thread(ftpDownFiles);
			thread.setName("downloadOnixXmlThread" + i);
			thread.start();
		}
	}

	@Override
	public void stopDownLoadFiles() {
		try {
			synchronized (this) {
				setFinished(true);
				setStop(true);
			}
			//FileUtils.saveDownLoadFileInfoToDB(id,dealFiles,FtpDownLoadBaseServiceInfo.FtpServiceType_OnixDownloadFile);
			dealFiles.clear();
		} catch (Exception e) {
			
		}
	}

	@Override
	public void finish() {
		try {
			synchronized (this) {
				setFinished(true);
				setStop(true);
			}
			dealFiles.clear();
		} catch (Exception e) {
			
		}
	}
	
	public void adddealItem(FtpFileInfoVo dealInfo,boolean save) {
		synchronized (this) {
			if(save)
				dealFiles.add(dealInfo);
			dealCount++;
			if(dealCount==bookTotalCount){
				setFinished(true);
				setStop(true);
			}	
		}
	}

}
